home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amoszine PD Edition 0
/
Amoszine PD Edition 0.adf
/
SOURCE_CODE
/
word_counter.AMOS
/
word_counter.amosSourceCode
Wrap
AMOS Source Code
|
1993-02-25
|
2KB
|
92 lines
'
' Text Utilities #1 - Word Counter
' (c) 1990 Jason D Banks
'
_LED_OFF
F$=Fsel$("","","Name Text File to","Count Words In")
' get filename
If F$="" Then Edit
_GETDATA[F$]
' find size of file
SIZE=Param
'
_LOADFILE[F$,SIZE]
POS=Start(15)
FINIS=POS+SIZE
WORDS=0
' load file into memory
While POS<FINIS
_GET_WORD
Inc WORDS
_LED_TOGGLE
' count words
Wend
' _LED_TOGGLE is used, so that it can be shown that the computer is
' still working, and has not crashed...
Print "Number of words in ";NAME$
Print "is ";WORDS
_LED_ON
'
' procedures from here
'
Procedure _GET_WORD
Shared POS,FINIS
VC$="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
CH$=Upper$(Chr$(Peek(POS)))
While Instr(VC$,CH$)=0 : Inc POS : CH$=Upper$(Chr$(Peek(POS))) : Wend
If POS>FINIS Then Pop Proc
While Instr(VC$,CH$)>0 : Inc POS : CH$=Upper$(Chr$(Peek(POS))) : Wend
If POS>FINIS Then Pop Proc
While Instr(VC$,CH$)=0 : Inc POS : CH$=Upper$(Chr$(Peek(POS))) : Wend
If POS>FINIS Then Pop Proc
' reads in a word and then exits
End Proc
Procedure _GETDATA[NAME$]
Erase 15
Reserve As Work 15,260
Dreg(1)=Varptr(NAME$) : Dreg(2)=-2
HANDLE=Doscall(-84)
If HANDLE=0 Then Pop Proc
Dreg(1)=HANDLE
Dreg(2)=Start(15)
WORKS=Doscall(-102)
If WORKS=0 Then Dreg(1)=HANDLE : DUMMY=Doscall(-90) : Pop Proc
LGTH=Leek(Start(15)+124)
Dreg(1)=HANDLE
DUMMY=Doscall(-90)
Erase 15
' RETURNS THE SIZE OF FILE NAME$ IN PARAM
' NOTE THAT BANK 15 IS USED
End Proc[LGTH]
Procedure _LOADFILE[NAME$,LGTH]
Erase 15
Reserve As Work 15,LGTH
Dreg(1)=Varptr(NAME$)
Dreg(2)=1005
HANDLE=Doscall(-30)
' = open file for reading
Dreg(1)=HANDLE
Dreg(2)=Start(15)
Dreg(3)=LGTH
RDIN=Doscall(-42)
' = read in file contents
Dreg(1)=HANDLE
DUMMY=Doscall(-36)
' = close file down
'
' loads the entire file into bank 15
End Proc
Procedure _LED_OFF
Poke 12574721,Peek(12574721) or 2
End Proc
Procedure _LED_ON
Poke 12574721,Peek(12574721) and 253
End Proc
Procedure _LED_TOGGLE
A=Peek(12574721)
If(A and 2)=2
_LED_ON
Else
_LED_OFF
End If
End Proc